package ga.wavaplayer.video {
	
	import ga.wavaplayer.net.WNetConnection;
	import ga.wavaplayer.net.WNetStream;
	
	import flash.events.Event;
	
	public class WHTTPVideo extends WVideo {
		
		public function WHTTPVideo(options:Object) {
			connection = new WNetConnection();
			connection.connect(null);
			
			stream = new WNetStream(connection);
			
			super(options);
			
			this.addEventListener(Event.ENTER_FRAME, _enterFrameHandler);
		}
		
		private function _enterFrameHandler(e:Event):void{
//			trace(stream.bytesLoaded);
		}
		
		override public function seek(ratio:Number):void {
			var loadedRatio:Number = stream.bytesLoaded / stream.bytesTotal;
			if (ratio - loadedRatio < 0) {
				stream.seek(stream.meta_data.duration * ratio);
			} else {
				stream.play(_url+'?start='+(stream.meta_data.duration * ratio));
			}
		}
	}
}
